package org.leumasjaffe.initiativeTracker.distributed.controller;

import static org.leumasjaffe.initiativeTracker.operator.InitiativeController.tracker;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.leumasjaffe.initiativeTracker.Constants;
import org.leumasjaffe.initiativeTracker.entity.Character;
import org.leumasjaffe.initiativeTracker.entity.PC;
import org.leumasjaffe.initiativeTracker.operator.CharacterLinker;
import org.leumasjaffe.initiativeTracker.operator.InitiativeController;
import org.leumasjaffe.initiativeTracker.view.InitiativeFrame;

import edu.wpi.heineman.xml.Message;
import edu.wpi.heineman.client.IMessageHandler;

@NonNullByDefault
public class NullRollHandler implements IMessageHandler {

	@SuppressWarnings("null")
	@Override
	public void process(Message response) {
		InitiativeController tracker = tracker(response.contents.getFirstChild()
				.getAttributes().getNamedItem("game").getNodeValue());
		for (CharacterLinker cc : tracker.list.getList()) {
			Character c = cc.getCharacter();
			c.nullInit();
			if (c instanceof PC)
				((PC) c).nullTemp();
		}
		if (Constants.client) {
			InitiativeFrame.getInstance().reset();
			InitiativeFrame.getInstance().repaint();
		}
	}

	@Override
	public IMessageHandler newCopy() {
		return new NullRollHandler();
	}

}
